Skip to content

Refactor projection binding to avoid redundant Convert nodes and impr…#37625

Open
Abde1rahman1 wants to merge 4 commits intodotnet:mainfrom
Abde1rahman1:cleanup/projection-binding-aot
Open

Refactor projection binding to avoid redundant Convert nodes and impr…#37625
Abde1rahman1 wants to merge 4 commits intodotnet:mainfrom
Abde1rahman1:cleanup/projection-binding-aot

Conversation

@Abde1rahman1
Copy link
Contributor

@Abde1rahman1 Abde1rahman1 commented Feb 4, 2026

  • I've read the guidelines for contributing and seen the walkthrough
  • I've posted a comment on an issue with a detailed description of how I am planning to contribute and got approval from a member of the team
  • The code builds and tests pass locally (also verified by our automated build checks)
  • Commit messages follow this format:
    Summary of the changes
  1. Core Expression Enhancements
    ProjectionBindingExpression: Introduced the UpdateType(Type type) method. Since Expressions are immutable, this allows creating a new instance with a refined type. This is crucial for changing the "expected type" of a projection without wrapping it in a UnaryExpression (Convert node).

  2. Shaper Logic Optimization
    ProjectionBindingExpressionVisitor.MatchTypes: Updated the logic to check if an expression is a ProjectionBindingExpression. Instead of returning Expression.Convert(expression, targetType), it now calls projectionBindingExpression.UpdateType(targetType). This results in a much flatter and cleaner shaper expression tree.

  3. Provider Clean-up (Relational & Cosmos)
    RelationalProjectionBindingExpressionVisitor: Removed several calls to .MakeNullable(). By passing the raw expression.Type, we avoid unnecessary MakeGenericType calls, which is a significant win for NativeAOT and trimming. The MatchTypes logic now handles necessary conversions more intelligently.

CosmosProjectionBindingExpressionVisitor: Applied the same clean-up to the Cosmos provider, bringing it up to parity with the relational implementation.

Fixes ##36572

  • Tests for the changes have been added (for bug fixes / features)
  • Code follows the same patterns and style as existing code in this repo

@Abde1rahman1 Abde1rahman1 requested a review from a team as a code owner February 4, 2026 00:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants